package main

import (
	"github.com/gomodule/redigo/redis"
	"fmt"
)

type BlockChain struct {
	blocks []*Block
	rds    *redis.Conn
}

func NewBlockChain() *BlockChain {
	c, err := redis.Dial("tcp", "193.112.125.22:63118", redis.DialPassword("Yb@123456#Red"))
	if err != nil {
		fmt.Println("connect redis fail")

	}

	defer c.Close()
	return &BlockChain{[]*Block{NewGenesisBlock(),c}}
}

func (b *BlockChain) AddBlockChain(data string) {
	prevBlock := b.blocks[len(b.blocks)-1]
	newBlock := NewBlock(data, prevBlock.Hash)
	b.blocks = append(b.blocks, newBlock)
}
